from urllib import request
import re
import random_proxy

proxy = {
    'http' : 'http://103.242.219.243:8080',
    'https' : 'http://103.242.219.243:8080'
}
#
# auth_proxy = {
#     'http' : 'alice:123456@120.78.166.84:6666',
#     'https' : 'alice:123456@120.78.166.84:6666'
# }

# p = random_proxy.Proxy()
# proxy = p.random_proxy()
# print(proxy)

# 代理管理器
proxy_handler = request.ProxyHandler(proxy)
opener = request.build_opener(proxy_handler)
request.install_opener(opener)

base_url = 'http://www.baidu.com/s?wd=ip'
response = request.urlopen(base_url)
html = response.read().decode('utf-8')

ip_pat = re.compile(r'class="c-gap-right">(.+?)</span>')
res = ip_pat.search(html)

if res is not None:
    print(res.group(1))


